package com.itheima.project_cloth.controller;

import com.itheima.project_cloth.pojo.Emp;
import com.itheima.project_cloth.pojo.JwtUtils;
import com.itheima.project_cloth.pojo.Result;
import com.itheima.project_cloth.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController

public class LoginController {
    @Autowired
    private LoginService loginService;

    @PostMapping("/login")
    public Result Login(@RequestBody Emp emp) {
        Emp emp1 = loginService.Login(emp);
        if (emp1 != null) {
            Map<String, Object> claims = new HashMap<>();
            claims.put("身份为", emp1.getLimitId());
            claims.put("name", emp1.getName());
            String s = JwtUtils.generateJwt(claims);
            return Result.success(s);

        }
       else {
           return Result.error("登录失败,用户名或密码错误");
        }

    }

}
